Announcement

Collapse
No announcement yet.

Question re }too good to be true" backtesting results...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question re }too good to be true" backtesting results...

    Hi all...have been testing an EFS script for forex, and for some reason I'm getting 100% accuracy on my short trades no matter how many hundreds of trades it backtests on (when i review the strategy analyzer report). I can't believe it, there's simply no way it's possible. Anyhow, I noticed that on a lot of the profitable short trades, the buy and sell times are on the same 5 minute bar. Can anyone please tell me what might be causing this?

  • #2
    asherisaac
    This can be caused by using Strategy.MARKET (ie the open of a bar) and Strategy.THISBAR to enter a trade where the signals are based on the close of that bar.
    You may want to try replacing Strategy.MARKET with Strategy.CLOSE or Strategy.THISBAR with Strategy.NEXTBAR.
    Alex

    Comment


    • #3
      There could be a flaw in the logic also, but the clue is:

      "Anyhow, I noticed that on a lot of the profitable short trades, the buy and sell times are on the same 5 minute bar."


      As Alex advises below, make sure you aren't using MARKET with THISBAR, but also verify that you aren't setting up some very small profit stop.

      If you can't find the problem feel free to post up the code and we can see if we can find the problem.

      G
      Garth

      Comment


      • #4
        guys, it seems i already have everything set for Strategy.NEXTBAR...here's the code. thanks in advance:

        // Asher's Trading Program

        var MAStudy1 = new MAStudy(50, 0, "Close", MAStudy.SIMPLE );
        var MAStudy2 = new MAStudy( 200, 0, "Close", MAStudy.SIMPLE );
        var MAStudy3 = new MAStudy( 19, 0, "Close", MAStudy.SIMPLE );
        var vADXDM = new ADXDMStudy(14);
        var vADXDM2 = new ADXDMStudy(45);
        var nTradeEntryPrice
        var nStopLevel;
        var nShortStopLevel;
        var nNewTrade;
        var nNewShortTrade;
        var ProfitTarget1 = .003;
        var stop = .006;
        var bullcross = 0;
        var bearcross = 0;
        var min = .0005
        var shortbullcross = 0;
        var shortbearcross = 0;
        function preMain() {

        setPriceStudy(true);
        setStudyTitle("");


        }

        function main() {


        var MA50 = MAStudy1.getValue(MAStudy.SIMPLE);
        var MA200 = MAStudy2.getValue(MAStudy.SIMPLE);
        var MA19 = MAStudy3.getValue(MAStudy.SIMPLE);
        var ADX = vADXDM.getValue(ADXDMStudy.ADX);
        var ADX2 = vADXDM2.getValue(ADXDMStudy.ADX);
        var MA10 = MA50; // alias
        var MA20 = MA200; // alias


        // if (Strategy.isLong() == true && (low() <= nTradeEntryPrice - .0025)) {
        // stopsell(); }
        if (Strategy.isShort() == true && (high() >= nTradeEntryPrice + .0025)) {
        shortcover(); }

        if (Strategy.isLong() == true && (high() >= nTradeEntryPrice + .002)) {
        nStopLevel = nTradeEntryPrice + .001; }

        if (Strategy.isShort() == true && (low() >= nTradeEntryPrice - .002)) {
        nShortStopLevel = nTradeEntryPrice - .001; }

        if (Strategy.isLong() == true && (high() >= nTradeEntryPrice + .004)) {
        nStopLevel = nTradeEntryPrice + .003; }

        if (Strategy.isShort() == true && (low() >= nTradeEntryPrice - .002)) {
        nShortStopLevel = nTradeEntryPrice - .003; }


        if (MA50 >= MA200 && (MA19 > MA50)) { shortbullcross = 1; }

        if (shortbullcross == 1 && (MA19 >= MA50 + .0005)) { nNewTrade = 1; shortbullcross = 0; }

        if (MA50 <= MA200 && (MA19 < MA50)) { shortbearcross = 1; }

        if (shortbearcross == 1 && (MA19 <= MA50 - .0005)) { nNewShortTrade = 1; shortbearcross = 0; }
        // if (bearcross == 1 && (MA19 == MA50)) { shortbearcross = 1; }
        // if (shortbearcross == 1 & (MA19 <= MA50 - .0005)) { nNewShortTrade = 1; shortbearcross = 1; }



        if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
        nNewTrade = 0;
        // Turn off NEW TRADE switchs
        }

        if (Strategy.isInTrade() == true && (nNewShortTrade == 1)) {
        nNewShortTrade = 0;
        // Turn off NEW TRADE switchs
        }

        if (Strategy.isInTrade() == true && (Strategy.isShort() == true)) {
        // Check if the profit target has been reached/breached
        if (low() <= (nTradeEntryPrice - ProfitTarget1)) {
        // Profit Target Breached, Execute Cover order.
        shortcover();
        }
        }
        if (Strategy.isInTrade() == true && (Strategy.isLong() == true)) {
        // Check if the profit target has been reached/breached
        if (high() >= (nTradeEntryPrice + ProfitTarget1))
        // Profit Target Breached, Execute Cover order.
        sell();
        }




        // executes the long stop if breached

        if (Strategy.isLong() == true) {

        if (low() <= nStopLevel) {
        stopsell();

        }

        }

        // executes the short stop if breached

        if (Strategy.isShort() == true) {

        if (high() >= nShortStopLevel) { shortstop(); } }




        // buys based on MFI, ADX/DMI, and Bollinger Bands...the **** it is.

        if (Strategy.isLong() == false && (bullcross == 0)) {

        if (

        MA10 > MA20 + min) { bullcross = 1; bearcross = 0; nNewTrade = 1; } }

        if (Strategy.isShort() == false && (bearcross == 0)) {

        if (

        MA10 < MA20 - min
        )
        { bearcross = 1; bullcross = 0; nNewShortTrade = 1; } }





        // buys

        if (
        (nNewTrade == 1) &&
        (Strategy.isLong() == false) &&
        (bullcross == 1) )


        {
        buy(); }
        //





        // shorts

        if ((nNewShortTrade == 1) && (Strategy.isShort() == false) && (bearcross == 1)
        // && (ADX >= 25)
        ) {
        goshort(); }







        }
        function postMain() {

        }



        function buy() {
        if (Strategy.isShort() == true) { shortcover(); }
        if (Strategy.isLong() == false) {
        Strategy.doLong("Buy Order", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
        drawTextRelative(0, close(), "BUY", Color.RGB(0,0,255), Color.RGB(255,255,255), Text.LEFT, "Arial", 14);
        nNewTrade = 1; nTradeEntryPrice = close(+1);
        nStopLevel = nTradeEntryPrice - stop; }

        }

        // function sellhalf() {
        // if (Strategy.isInTrade() == true) {
        // Strategy.doSell("Sell Order","Strategy.MARKET, Strategy.NEXTBAR, Strategy.D

        function sell() {

        Strategy.doSell("Sell Order", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
        drawTextRelative(0, close(), "SELL", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 14);
        nNewTrade = 0; bearcross = 0;
        bullcross = 0;
        }

        function closeout() {

        Strategy.doSell("Sell Order", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
        drawTextRelative(0, close(), "CLOSEOUT", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 14);
        nNewTrade = 0;
        }

        function goshort() {

        if (Strategy.isLong() == true) { sell(); }
        if (Strategy.isShort() == false) {
        Strategy.doShort("Short Sale", Strategy.MARKET, Strategy.NEXTBAR, Strategy.DEFAULT);
        drawTextRelative(0, close(), "GO SHORT", Color.RGB(0,0,255), Color.RGB(255,255,255), Text.LEFT, "Arial", 14);
        nNewShortTrade = 1; nTradeEntryPrice = close(+1); nNewTrade = 0;
        nShortStopLevel = nTradeEntryPrice + stop;

        } }

        function stopsell() {
        Strategy.doSell("Stop Sell", Strategy.STOP, Strategy.THISBAR,
        Strategy.ALL, nStopLevel);
        drawTextRelative(0, close(), "STOP", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 16);

        }

        function shortcover() {
        if (Strategy.isShort() == true) {
        Strategy.doCover("Short Cover", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
        nNewShortTrade = 0;
        drawTextRelative(0, close(), "SHORT COVER", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 14);
        bearcross = 0; bullcross = 0;
        }
        }
        function shortstop() {
        Strategy.doCover("Short Stop", Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nShortStopLevel);
        nShortStop = 0;
        drawTextRelative(0, close(), "STOP", Color.RGB(155,0,0), Color.RGB(255,255,255), Text.LEFT, "Arial", 16);

        }

        Comment


        • #5
          asherisaac,

          I don't have forex, so I backtested on ES #F, 5 and it didn't show the same issue. Out of 897 trades 42.02% was the % profitable. I will try some other symbols, but unless I can reproduce it will make it really hard to debug.

          Garth
          Garth

          Comment


          • #6
            OK, I haven't been able to reproduce it, but looking at the code I do have a few comments.

            1) Your price movement for stops is very tight...since I don't trade forex I have no idea how it moves. Perhaps this isn't tight for it, but for everything I trade, it is very tight and will get u stopped out on the same bar you enter for most symbols.

            2) I think you have a mix up in your stops. For both long and short you are seeing if the High/Low is greater than the entry price. I suspect you want to check to see if the low is higher than entry and the high lower...but since I usually do my stops very different than this (ie: On a long I check is the low was lower or equal to my stop and on a short check is the high was higher or equal to my stop) I'm not sure. But it looks messed up to me.

            Garth
            Garth

            Comment


            • #7
              gspiker, i think you hit it on the head with suggestion #2. thanks! i had a simple mix up in my trailing stop alogrithm. i feel embarassed for taking the board's time for such a trivial issue! (i thought it was something more fundamental). you are all so kind for taking the time to read the code, etc.

              i have another question re backtesting that i haven't been able to figure out. i'm trying to test 5-min charts over a 30-day period (for eur/usd). i have an advanced chart window set up with a proper time template, but the backtesting keeps testing on only a few days. any tips on controlling the exact backtesting period with 5-min charts?

              tia,

              asher

              Comment


              • #8
                asher,

                Typically this is because you haven't set the correct time template in the Back Testing setup window. I know I have missed that a few times, its easy to do.

                Also, just to verify you are using the right TT in the Back Testing setup window, I would make sure the main chart is using the same TT and interval...it not only makes it easier to verify everything, but I have seen some odd cases (which I can't regularly reproduce, so it may be just my user error at times) where I would swear that the backtester decided to use the interval on the main chart, rather than what I had set in the setup window.

                Garth
                Garth

                Comment

                Working...
                X